package com.internetCafes.spms.web.sys.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.sys.dao.RoleMenuInfoMapper;
import com.internetCafes.spms.web.sys.service.RoleMenuInfoService;
import org.springframework.transaction.annotation.Transactional;


/**
 * 角色与菜单对应关系 RoleMenuInfoService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-10-29 00:11:51
 */
@Service("roleMenuInfoService")
public class RoleMenuInfoServiceImpl implements RoleMenuInfoService {

    @Autowired
    private RoleMenuInfoMapper roleMenuInfoMapper;

    @Override
    public void deleteBatchByRoleIdList(Long[] roleIdList) {
        roleMenuInfoMapper.deleteBatchByRoleIdList(roleIdList);
    }

    @Override
    @Transactional
    public void saveOrUpdate(Long roleId, List<Long> menuIdList) {
        //先删除角色与菜单关系
        roleMenuInfoMapper.delete(roleId);

        if(menuIdList.size() == 0){
            return ;
        }

        //保存角色与菜单关系
        Map<String, Object> map = new HashMap<>();
        map.put("roleId", roleId);
        map.put("menuIdList", menuIdList);
        roleMenuInfoMapper.save(map);
    }

    @Override
    public List<Long> queryMenuIdList(Long roleId) {
        return roleMenuInfoMapper.queryMenuIdList(roleId);
    }

    @Override
    public int deleteBatch(Long[] roleIds) {
        return roleMenuInfoMapper.deleteBatch(roleIds);
    }
}